package action.releasework;

import java.util.Date;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.Result;
import service.releaseWorkService;
import util.DateTool;
import model.Work;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

@Namespace("")
@Action(
	value="releaseWork",
	results={
			@Result(name="success",type="chain",location="AdminqueryAllWork")
	}		
)
public class releaseWork extends ActionSupport{
	private String title;
	private String content;
	private String deadline;
	public String execute() throws Exception{
		 String author_id="user";
		 Date date;
		 Date now=new Date();
		 Work work=new Work();
		 work.setTitle(title);
         work.setContent(content);
         date=DateTool.StringtoDate(deadline);
         ActionContext ac=ActionContext.getContext();
         author_id=(String)ac.getSession().get("user_id");
         work.setAuthor_id(author_id);
         work.setReleasedate(now);
         work.setDeadline(date);
         
         releaseWorkService rws=new releaseWorkService();
         return rws.release(work);
	}
	
	public String getTitle() {
		return title;
	}
	public void setTitle(String title) {
		this.title = title;
	}
	public String getContent() {
		return content;
	}
	public void setContent(String content) {
		this.content = content;
	}
	public String getDeadline() {
		return deadline;
	}
	public void setDeadline(String deadline) {
		this.deadline = deadline;
	}
}